/**
 * Project: springyounger.lottery.biz.user
 * 
 * File Created at 2010-3-19
 * $Id$
 * 
 * Copyright 2009 Zjut Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Zjut Edu. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Zjut Edu.
 */
package com.springyounger.lottery.service.user;

import java.util.List;

import org.apache.log4j.Logger;

import com.springyounger.lottery.dal.dao.UserDao;
import com.springyounger.lottery.dal.dataobject.User;

/**
 * TODO Comment of UserService
 * 
 * @author springyounger
 */
public class UserService {
    private Logger  logger = Logger.getLogger(UserService.class);
    private UserDao userDao;

    /**
     * 获取用户列表
     * 
     * @return
     */
    public List<User> getUsers(int pageIndex, int pageSize) {
        try {
            return userDao.getUsers(pageIndex, pageSize);
        } catch (Exception e) {
            logger.error("获取用户列表失败!", e);
            return null;
        }
    }

    /**
     * 获取普通用户总数
     * 
     * @return
     */
    public int getAllUserCount() {
        try {
            return userDao.getAllUserCount();
        } catch (Exception e) {
            logger.error("获取普通用户总数失败!", e);
            return 0;
        }
    }

    /**
     * 模糊查询用户的总数
     * 
     * @param username
     * @return
     */
    public int getLikeUserCount(String username) {
        try {
            return userDao.getLikeUserCount(username);
        } catch (Exception e) {
            logger.error("模糊查询用户的总数失败", e);
            return 0;
        }
    }

    /**
     * 模糊查询用户列表
     * 
     * @param pageIndex
     * @param pageSize
     * @param username
     * @return
     */
    public List<User> getLikeUserByName(int pageIndex, int pageSize, String username) {
        try {
            return userDao.getLikeUserByName(pageIndex, pageSize, username);
        } catch (Exception e) {
            logger.error("模糊查询用户列表失败", e);
            return null;
        }
    }

    /**
     * 用户名查找用户
     * 
     * @param username
     * @return
     */
    public User getUser(String username) {
        try {
            return (User) userDao.getUser(username);
        } catch (Exception e) {
            logger.error("根据用户名获取用户失败!", e);
            return null;
        }
    }

    /**
     * 密码和用户名查找
     * 
     * @param user
     * @return
     */
    public User getUser(User user) {
        try {
            return (User) userDao.getUser(user);
        } catch (Exception e) {
            logger.error("登陆时，获取用户失败", e);
            return null;
        }
    }

    /**
     * 创建用户
     * 
     * @param user
     * @return
     */
    public boolean insertUser(User user) {
        try {
            userDao.insertUser(user);
            return true;
        } catch (Exception e) {
            logger.error("创建用户失败!", e);
            return false;
        }
    }

    /**
     * 更新用户
     * 
     * @param user
     * @return
     */
    public boolean updateUser(User user) {
        try {
            userDao.updateUser(user);
            return true;
        } catch (Exception e) {
            logger.error("更新用户失败!", e);
            return false;
        }
    }

    /**
     * 删除用户
     * 
     * @param userid
     * @return
     */
    public boolean deleteUser(int userid) {
        try {
            userDao.deleteUser(userid);
            return true;
        } catch (Exception e) {
            logger.error("删除用户失败!", e);
            return false;
        }
    }

    /**
     * @param userDao the userDao to set
     */
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
